<template>

	<view class="map-content">
		<map :longitude="mapData.longitude" :latitude="mapData.latitude" :circles="mapData.circles"
			:markers="mapData.markers" scale="13" @markertap="markertap"></map>
		<view id='content' class="detailBox" :style="[
			{
			'height':minHeight+'%',
			'transform':'translateY('+translateY+'%)',
			'backgroundColor':bgColor
			}, 
		]" @touchstart="fingerstart" @touchend="fingerend">
			<view v-if="showLine" class="popLine"></view>
			<view v-if="!showLine" class="popClose" @click="closePopBox">
				<u-icon name="close" :size="20"></u-icon>
			</view>
			<!-- 自定义内容插槽 -->
			<slot name="detail">
				<view class="block classify-tab-block">
					<view class="tab-content">
						<view class="active tab-item">附近职位</view>
						<!-- <view @click="goCircle" class="tab-item">职友圈</view> -->
					</view>
				</view>
					<view class="block list-block">
						<view
							@click="navigate('/page_other/job_hunting/job_detail/index?id='+item.id+'&jobType='+item.jobType)"
							class="list-item" v-for="(item,index) in list" :key="item.id">
							<view class="list-info">
								<view class="title">{{item.jobTitle}}</view>
								<view class="address iconfont icon-dizhi">{{item.jobAddress}}</view>
								<view class="label-block">
									<view class="label-item" v-for="label in item.label">{{label}}</view>
								</view>
								<view class="wage">{{item.minSalary}}-{{item.maxSalary}}<text class="unit">元</text>
								</view>
							</view>
							<view class="detail-info">
								<view class="name">{{item.comRecruiters.comPosition}}</view>
								<image mode="aspectFill" :src="item.comRecruiters.user.faceUrl" class="photo"></image>
								<view class="apply-btn">申请</view>
							</view>
						</view>
					</view>
				
			</slot>
		</view>
	</view>

</template>

<script>
	import {
		getPublishApi
	} from '@/api/job_hunting.js';
	export default {
		props: {
			// 高度
			boxHeihgt: {
				type: Number,
				default: 0
			},
			// 背景色
			bgColor: {
				type: String,
				default: "#F2F6FF"
			},
			// 控制初始是否显示
			startShow: {
				type: Boolean,
				default: false
			},
			// 是否显示线
			showLine: {
				type: Boolean,
				default: true
			},
			// 上下滑动 超过多少距离触发 updownDistance
			updDistance: {
				type: Number,
				default: 160
			},
		},
		watch: {
			'startShow': {
				handler(n, o) {
					this.isHide = !n;
				},
				deep: true,
				immediate: true
			}
		},
		data() {
			return {
				list: [],
				page: 1,
				limit: 4,
				mapData: {
					longitude: 98.510165,
					latitude: 39.737452,
					circles: [{
						latitude: '',
						longitude: '',
						color: '#7cb5ec88',
						fillColor: '#7cb5ec88',
						radius: 800,
						strokeWidth: 2
					}],
					markers: [{
							id: 9, // Number
							title: '1', // String-标注点名
							rotate: 0, // Number - 顺时针旋转的角度，范围 0 ~ 360，默认为 0
							alpha: 1, // 默认1，无透明，范围 0 ~ 1
							latitude: 0,
							longitude: 0,
							width: 30,
							height: 36,
							iconPath: 'https://dunhuang.gshwsc.com/api/file/91885/dunhuang/lMkpNQQOqj.png', // 显示的图标
						}, {
							id: 0,
							longitude: 98.499888,
							latitude: 39.707162,
							title: '甘肃大禹节水股份有限公司',
							iconPath: 'https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/map/mark.png',
							width: 30,
							height: 30,
							anchor: {
								x: 0.5,
								y: 0.5
							},
							callout: {
								content: "甘肃大禹节水股份有限公司",
								borderRadius: 5,
								display: "ALWAYS",
								padding: 7,
								bgColor: "#FFFFFF"
							}
						},
						{
							id: 1,
							longitude: 98.516076,
							latitude: 39.747026,
							title: '中国联通酒泉分公司',
							iconPath: 'https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/map/mark.png',
							width: 30,
							height: 30,
							anchor: {
								x: 0.5,
								y: 0.5
							},
							callout: {
								content: "中国联通酒泉分公司",
								borderRadius: 5,
								display: "ALWAYS",
								padding: 7,
								bgColor: "#FFFFFF"
							}
						}, {
							id: 2,
							longitude: 98.492646,
							latitude: 39.739391,
							title: '万达广场',
							iconPath: 'https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/map/mark.png',
							width: 30,
							height: 30,
							anchor: {
								x: 0.5,
								y: 0.5
							},
							callout: {
								content: "万达广场",
								borderRadius: 5,
								display: "ALWAYS",
								padding: 7,
								bgColor: "#FFFFFF"
							}
						}, {
							id: 3,
							longitude: 98.50878,
							latitude: 39.736007,
							title: '天宝大景区',
							iconPath: 'https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/map/mark.png',
							width: 30,
							height: 30,
							anchor: {
								x: 0.5,
								y: 0.5
							},
							callout: {
								content: "天宝大景区",
								borderRadius: 5,
								display: "ALWAYS",
								padding: 7,
								bgColor: "#FFFFFF",
							}
						}
					],
				},
				minHeight: 90,
				translateY: 70,
				isHide: true,
				boxPadBottom: 0,
				// 根据滑动设置位置
				changeTop: 0,
				// 是否固定高度
				showMax: false,
				// 记录起始位置
				startData: {
					clientX: '',
					clientY: ''
				}
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			markertap(e) {
				let markerId = e.detail.markerId;

				uni.navigateTo({
					url: '/page_other/company/info'
				})
			},
			// 当按下去的时候
			fingerstart(e) {

				// 记录 距离可视区域左上角 左边距 和 上边距
				this.startData.clientX = e.changedTouches[0].clientX;
				this.startData.clientY = e.changedTouches[0].clientY;

			},
			// 当抬起来的时候
			fingerend(e) {

				// 当前位置 减去 按下位置 计算 距离
				const subX = e.changedTouches[0].clientX - this.startData.clientX;
				const subY = e.changedTouches[0].clientY - this.startData.clientY;
				if (subY > this.updDistance || subY < -this.updDistance) {
					if (subY > this.updDistance) {
						// this.bottomscroll(subY);
						this.showMax = false;
						this.getDomTop()
					} else if (subY < -this.updDistance) {
						// this.topscroll(subY);
						this.showMax = true;
						this.getDomTop()
					}
				}
			},
			// 获取元素的top值
			getDomTop() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.detailBox').boundingClientRect(data => {
					if (data) {
						// 上滑
						this.translateY = 0;
						if (this.showMax) {} else {
							// 下滑
							this.translateY = 70;
						}
					}
				}).exec();
			},
			chosenPosition() {
				uni.getLocation({
					isHighAccuracy: true,
					success: (current) => {
						this.mapData.markers[0].latitude = current.latitude;
						this.mapData.markers[0].longitude = current.longitude;
						this.mapData.circles[0].latitude = current.latitude;
						this.mapData.circles[0].longitude = current.longitude;
					},
					fail: (e) => {
						this.showToast('获取位置失败，请重试！');
					}
				})
			},
			getList() {
				let config = {
					page: this.page,
					limit: this.limit
				}
				getPublishApi(config).then((res) => {
					this.list = res.list ?? [];
					console.log(this.list)
				})
			}

		},
		onLoad() {
			this.chosenPosition();
			this.getList();
		}
	}
</script>

<style lang="scss" scoped>
	$box-shadow: 0 0 10px 0 #efefef;
	.map-content {
		width: 100%;
		height: 100vh;

		map {
			width: 100%;
			height: 100%;
		}
	}

	.detailBox {
		position: fixed;
		width: 100%;
		height: auto;
		bottom: 0;
		left: 0;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		overflow-y: auto;
		transition: all .5s;
		z-index: 99999;
		.block.classify-tab-block {
			width: 100%;
			height: 50rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
		
			.tab-content {
				display: flex;
				flex-direction: row;
				justify-content: left;
		
				.tab-item {
					padding: 10rpx 30rpx;
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 20rpx;
					flex: none;
				}
		
				.tab-item.active {
					background: url("https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/home/tab_selected_bg.png") no-repeat right bottom;
					background-size: 70%;
				}
			}
		
			.publish-btn {
				width: 45rpx;
			}
		
			.iconfont {
				font-size: 32rpx;
				font-weight: bold;
				color: #000;
			}
		}
		.block.list-block{
			
				box-shadow: none;
				display: flex;
				flex-direction: column;
				margin-bottom: 0;
			
				.list-item {
					background: #fff;
					border-radius: 10rpx;
					box-shadow: $box-shadow;
					padding: 20rpx;
					display: flex;
					flex-direction: row;
					justify-content: center;
					margin: 20rpx 40rpx;
			
					.detail-info {
						width: 180rpx;
						height: 200rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: center;
						align-items: center;
			
						.name {
							width: 110rpx;
							font-size: 24rpx;
							color: #999;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							text-align: center;
							text-indent: 20rpx;
						}
			
						.photo {
							width: 70rpx;
							height: 70rpx;
							border-radius: 100%;
							background: #efefef;
						}
			
						.apply-btn {
							border: 1px solid #FE7526;
							border-radius: 8rpx;
							color: #FE7526;
							font-size: 24rpx;
							padding: 8rpx 28rpx;
							position: relative;
							left: 30rpx;
						}
					}
			
					.list-info {
						width: calc(100% - 180rpx);
						display: flex;
						flex-direction: column;
			
						view {
							width: 100%;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
			
						.title {
							color: #000;
							font-weight: bold;
							font-size: 34rpx;
						}
			
						.address {
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
						}
			
						.label-block {
							font-size: 24rpx;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							justify-content: left;
							margin-top: 20rpx;
			
							.label-item {
								padding: 8rpx 20rpx;
								background: #F5F6F8;
								color: #999;
								margin: 0 10rpx 20rpx 0;
							}
						}
			
						.wage {
							color: #FE7526;
							font-size: 36rpx;
							font-weight: bold;
			
							.unit {
								font-size: 28rpx;
								font-weight: normal;
							}
						}
					}
				}
			
				.list-item:last-child {
					margin-bottom: 0;
				}
			
				.person-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					padding: 0 30rpx;
					margin-bottom: 30rpx;
			
					.info-block,
					.job-block {
						width: 100%;
						padding: 20rpx 0;
					}
			
					.info-block {
						border-bottom: 1px solid #efefef;
						display: flex;
						flex-direction: row;
						align-items: center;
			
						.user-photo {
							width: 100rpx;
							height: 100rpx;
							border-radius: 50%;
						}
			
						.info {
							width: calc(100% - 120rpx);
							margin-left: 20rpx;
							font-size: 26rpx;
			
							.name {
								font-weight: bold;
								font-size: 34rpx;
							}
			
							.other-item {
								display: flex;
								flex-direction: row;
			
								.other {
									color: #999;
									margin-top: 14rpx;
									overflow: hidden;
									text-overflow: ellipsis;
									white-space: nowrap;
								}
							}
			
						}
					}
			
					.job-block {
						display: flex;
						flex-direction: row;
						align-items: center;
			
						.job {
							width: calc(100% - 140rpx);
							display: flex;
							flex-direction: column;
							justify-content: center;
			
							.label-block {
								width: 100%;
								display: flex;
								flex-direction: row;
								flex-wrap: wrap;
			
								.label-item {
									background: #F4F5F7;
									color: #999;
									font-size: 24rpx;
									padding: 4rpx 10rpx;
									margin-right: 20rpx;
									margin-bottom: 20rpx;
								}
							}
			
							.job-content {
								width: 100%;
								font-size: 26rpx;
							}
						}
			
						.btn-block {
							width: 140rpx;
							display: flex;
							align-items: center;
							justify-content: center;
			
							.btn {
								padding: 6rpx 26rpx;
								border: 1px solid #FE7526;
								border-radius: 6rpx;
								color: #FE7526;
								font-size: 24rpx;
							}
						}
					}
				}
			
				.person-item:last-child {
					margin-bottom: 0;
				}
			
				.circle-item {
					display: flex;
					flex-direction: column;
					padding: 30rpx 30rpx 15rpx 30rpx;
			
					.info-block {
						display: flex;
						align-items: center;
			
						.user-photo {
							width: 70rpx;
							border-radius: 35rpx;
							margin-right: 15rpx;
						}
			
						.name {
							width: calc(100% - 70rpx - 15rpx);
							font-size: 30rpx;
						}
					}
			
					.content-block {
						font-size: 30rpx;
						padding: 15rpx 0 0rpx 0;
			
						.part-content {
							line-height: 50rpx;
							display: -webkit-box;
							overflow: hidden;
							/*超出隐藏*/
							text-overflow: ellipsis;
							/*隐藏后添加省略号*/
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 3; //想显示多少行
			
							.keyword {
								color: #0b93e1;
							}
			
							.aite {
								color: #0b93e1;
							}
						}
			
						.content {
							line-height: 50rpx;
			
							.keyword {
								color: #0b93e1;
							}
			
							.aite {
								color: #0b93e1;
							}
						}
			
						.all {
							width: 60rpx;
							;
							margin-top: 10rpx;
							color: #ff7626;
						}
					}
			
					.video-block {
						width: 100%;
			
						.video-item {
							width: 400rpx;
							height: 300rpx;
						}
					}
			
					.operate-block {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						align-items: center;
			
						.time {
							color: #999999;
							font-size: 28rpx;
						}
			
						.operate {
							display: flex;
							align-items: center;
							height: 70rpx;
			
							.operate-item {
								width: 320rpx;
								height: 70rpx;
								border-radius: 6rpx;
								background-color: #616161;
								display: flex;
								flex-direction: row;
			
								.item {
									width: calc(100% / 2 - 1px);
									display: flex;
									flex-direction: row;
									align-items: center;
									justify-content: center;
									border-right: 1px solid rgba(0, 0, 0, .1);
			
									.operate-icon {
										width: 30rpx;
										margin-right: 5rpx;
									}
			
									.operate-name {
										font-size: 28rpx;
										color: #ccc;
									}
								}
			
								.item:last-child {
									border: 0;
								}
							}
			
							.icon {
								width: 65rpx;
								margin-left: 10rpx;
							}
						}
			
					}
			
					.comment-block {
						background-color: #f0f0f0;
						border-radius: 6rpx;
						padding: 20rpx;
						margin-top: 10rpx;
						display: flex;
						flex-direction: column;
			
						.like-item {
							width: 100%;
							margin: auto;
			
							.like-icon {
								width: 35rpx;
								position: relative;
								top: 4rpx;
							}
			
							.name {
								font-size: 28rpx;
								color: #0b92e0;
								margin-left: 7rpx;
							}
			
							.comma {
								color: #0b92e0;
							}
						}
			
						.divide-line {
							padding-bottom: 20rpx;
							border-bottom: 1px solid #ccc;
						}
			
						.comment-list {
							display: flex;
							flex-direction: column;
							padding-top: 10rpx;
			
							.comment-item {
								.content {
									font-size: 30rpx;
									line-height: 50rpx;
									display: -webkit-box;
									overflow: hidden;
									/*超出隐藏*/
									text-overflow: ellipsis;
									/*隐藏后添加省略号*/
									-webkit-box-orient: vertical;
									-webkit-line-clamp: 3; //想显示多少行
			
									.name {
										color: #0b92e0;
									}
								}
							}
						}
					}
				}
			
		}
	}

	.popLine {
		width: 115rpx;
		height: 10rpx;
		border-radius: 28rpx;
		background-color: #C9CACD;
		margin: 20rpx auto 35rpx;
	}

	.popClose {
		width: calc(100% - 80rpx);
		display: flex;
		justify-content: flex-end;
		margin: 30rpx 40rpx 10rpx 40rpx;
	}
</style>
